------------------------------------------------------------------------------------------------------------------
USE ReportesGerenciales;
GO

----------------------------------------------------------------------------------------------------------------
DROP FUNCTION EscapeString;
GO

CREATE FUNCTION EscapeString (@val varchar(128))
RETURNS varchar(128)
AS
BEGIN
	IF @val IS NULL RETURN 'NULL';
	RETURN '''' + REPLACE(@val, '''', '''''') + '''';
END
GO

----------------------------------------------------------------------------------------------------------------
DROP FUNCTION EscapeStringForLike;
GO

CREATE FUNCTION EscapeStringForLike (@val varchar(128))
RETURNS varchar(128)
AS
BEGIN
	IF @val IS NULL RETURN 'NULL';
	RETURN '''%' + REPLACE(@val, '''', '''''') + '%''';
END
GO

----------------------------------------------------------------------------------------------------------------
DROP FUNCTION WhenNull;
GO

CREATE FUNCTION WhenNull (@val varchar(128), @a varchar(128), @b varchar(128))
RETURNS varchar(128)
AS
BEGIN
	IF @val IS NULL RETURN @a;
	RETURN @b;
END
GO
